fix(cache,da): drop finalized snapshot entries on restore and drain DA subscription channel#3385
Conversation
…A subscription channel Two memory fixes for long-running nodes: Cache restore: the DA-inclusion snapshot is only written on graceful shutdown, so after a crash (e.g. OOM kill) the restored snapshot can contain heights already below the persisted DA-included watermark. The inclusion loop never evicts below its watermark, so those placeholder entries leaked for the process lifetime and were re-persisted on every subsequent save, growing the snapshot monotonically across crash/restart cycles. RestoreFromStore now skips entries at or below the persisted DAIncludedHeight; skipped entries still seed maxDAHeight so DaHeight() is unchanged. DA subscription: the Subscribe wrapper goroutine exited on ctx cancellation without draining the underlying jsonrpc channel, leaving the go-jsonrpc delivery goroutine blocked on send — it never observed the cancellation and never closed its channel, leaking one goroutine per watchdog reconnect. The wrapper now drains the raw channel on exit. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughCache restoration now accepts a finalized-height watermark, skips finalized placeholders while retaining DA height, and passes persisted metadata through manager restoration. DA subscription shutdown now drains the underlying JSON-RPC channel. ChangesWatermarked cache restoration
DA subscription shutdown
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant CacheManager
participant Store
participant Cache
CacheManager->>Store: read DAIncludedHeightKey
CacheManager->>Cache: restore with finalized height
Cache->>Cache: update DA height from snapshot
Cache->>Cache: install only non-finalized placeholders
sequenceDiagram
participant Caller
participant Subscribe
participant JSONRPC
Caller->>Subscribe: cancel context
Subscribe->>JSONRPC: drain raw channel
JSONRPC-->>Subscribe: close channel
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
The latest Buf updates on your PR. Results from workflow CI / buf-check (pull_request).
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3385 +/- ##
==========================================
- Coverage 62.33% 62.32% -0.01%
==========================================
Files 120 120
Lines 13444 13452 +8
==========================================
+ Hits 8380 8384 +4
- Misses 4124 4126 +2
- Partials 940 942 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Overview
Two memory fixes for long-running nodes, found while investigating a user report of sustained memory growth (+201 MiB/min) and OOM kills on syncing nodes.
1. Cache restore leaks stale placeholders across crash/restart cycles
The DA-inclusion snapshot is only persisted on graceful shutdown (
Components.Stop). After a crash (e.g. OOM kill, SIGKILL), the node restores a snapshot from the last graceful shutdown, which can contain heights already at or below the persistedDAIncludedHeightwatermark. Since:DeleteHeightfor heights it advances through, andIsHeightDAIncludedshort-circuitstruebelow the watermark so those entries are never consulted,restored placeholders below the watermark were never evicted, and were re-persisted on the next graceful save — so the snapshot grew monotonically across crash/restart cycles.
Cache.RestoreFromStorenow takes the finalized height and skips entries at or below it. Skipped entries still contribute tomaxDAHeight, soDaHeight()semantics are unchanged.manager.RestoreFromStorereadsDAIncludedHeightKeyand passes it through; a read error falls back to unfiltered restore instead of failing startup.The pre-existing comment in
TestManager_SaveAndRestoreFromStorealready described this as the intended behavior ("The cache entry is not restored — this is correct and intentional") — the code just didn't do it. It now does, and the test asserts it.2. DA subscription goroutine leak on reconnect
The
client.Subscribewrapper goroutine exited on ctx cancellation without draining the underlying jsonrpc channel. The go-jsonrpc delivery goroutine blocked on send into that channel never observed the cancellation and never closed its channel — leaking one goroutine per watchdog reconnect (observed in the field asSubscribe.func1goroutines doubling). The wrapper now drains the raw channel on exit, matching what its own doc comment previously required of callers.Testing
TestCache_RestoreFromStore_SkipsFinalizedEntriescovering partial and fully-stale snapshotsTestManager_SaveAndRestoreFromStorenow asserts finalized heights are not restoredgo test ./block/...,go vet,golangci-lintall cleanNote: this does not address the primary OOM driver from the same investigation (unbounded
pendingEventsbuffering when DA catchup outpaces execution) — that needs a separate backpressure change.🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Reliability